<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ include file="include.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ include file="menu.jsp" %>


<link type="text/css" href="../css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="../js/ui.datetimepicker.js"></script>

<script type="text/javascript">

    $(function() {

        // dateTimePicker
        $('.datetimepicker').datetimepicker({ dateFormat: 'dd-mm-yy',timeFormat: ' hh:ii:ss' });
    });
</script>

<style type="text/css">
    .title {
        text-align: center;
        font-family: sans-serif;
        font-size: larger;
        color: #6699cc;
        width: 1000px;
        margin: 0 auto;
    }

    .grid {
        width: 1000px;
        margin: 0 auto;

    }

    .grid table {
        width: 100%;
    / / border-collapse : collapse;
        font-size: 12px;
        font-family: Verdana;

    }

    .table_head {
        font-size: medium;
        text-align: center;
        font-weight: bold;
        background-color: #6699cc;
    }

    tr {
        height: 25px;
    }

    .form {
        width: 1000px;
        margin: 0 auto;
        font-family: sans-serif;
        font-style: normal;

    }

    .form select {
        width: 300px;
        border: medium solid #FFFFFF;
        background-color: #e0e0e0;
    }

    .form input {
        width: 300px;
    }

    input.button {
        cursor: pointer;
        background-color: #FFCC00;
        font-weight: bold;
        width: 100px;

    }

    .form td {
        font-size: x-small;
        font-weight: bold;

    }

    .required {
        color: red;
    }

    .completed {
        text-align: center;
        background-color: #E1FFA7;
    }

    .not_started {
        text-align: center;
        background-color: #FFDDDC;
    }

    .execute {
        text-align: center;
        background-color: #FEFBC3;
    }

    .table_row_1 {
        background-color: #e0e0e0;
    }
</style>

<div class="title">
    Управление событиями
</div>
<div class="grid">
    <div class="events">
        <table>
            <tr class="table_head">
                <td>Событие</td>
                <td>Период</td>
                <td>Ресурс</td>
                <td>Пользователь</td>
                <td>Статус</td>
                <td></td>
                <td></td>

            </tr>
            <c:set var="count" value="0" scope="page"/>
            <c:forEach items="${events}" var="e">
                <c:set var="count" value="${count + 1}" scope="page"/>
                <tr <c:if test="${(count % 2) == 0}"><c:out value="class=table_row_1"/></c:if> >
                    <td><c:out value="${e.eventName}"/></td>
                    <td>Начало - <c:out value="${e.startDate}"/><br>Конец - <c:out value="${e.finishDate}"/></td>
                    <td><c:out value="${e.resource.hostName}"/></td>
                    <td><c:out value="${e.user.lastName} ${e.user.firstName}"/></td>
                    <c:set var="statusName" value="${e.status.statusName}"/>
                    <td

                            <c:if test="${statusName eq 'completed'}"><c:out value="class=completed"/></c:if>
                            <c:if test="${statusName eq 'not_started'}"><c:out value="class=not_started"/></c:if>
                            <c:if test="${statusName eq 'execute'}"><c:out value="class=execute"/></c:if>
                            >
                        <c:out value="${e.status.alias}"/>
                    </td>

                    <c:set var="editValue" value="/user/createEvent.htm"/>
                    <c:set var="deleteValue" value="/user/deleteEvent.htm"/>

                    <security:authorize ifAllGranted="ROLE_ADMIN">
                        <c:set var="editValue" value="/admin/createEvent.htm"/>
                        <c:set var="deleteValue" value="/admin/deleteEvent.htm"/>
                    </security:authorize>


                    <c:url var="editUrl" value="${editValue}">
                        <c:param name="action" value="edit"/>
                        <c:param name="eventId" value="${e.eventId}"/>
                    </c:url>
                    <c:url var="deleteUrl" value="${deleteValue}">
                        <c:param name="action" value="delete"/>
                        <c:param name="eventId" value="${e.eventId}"/>
                    </c:url>
                    <td align="center"><a href="${editUrl}"><img style="border:0px;" src="../images/edit.png"
                                                                 alt="Edit"></a></td>
                    <td align="center"><a href="${deleteUrl}"><img style="border:0px;" src="../images/delete_red.png"
                                                                   alt="Delete"></a></td>

                </tr>

            </c:forEach>
        </table>

    </div>
</div>

<div class="form">
    <form:form commandName="newEvent" cssClass="form">
        <fieldset>
            <table>
                <tr>
                    <td>Событие <span class="required">*</span></td>
                    <td><form:input path="eventName"/></td>
                    <td><form:errors path="eventName" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>Описание</td>
                    <td><form:textarea path="description" cols="35" rows="5"/></td>
                    <td><form:errors path="description" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>Ресурс<span class="required">*</span></td>
                    <td><form:select path="resource">
                        <form:options items="${resources}" itemValue="resourceId" itemLabel="hostName"/>
                    </form:select>
                    </td>
                    <td><form:errors path="resource" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>Start Date <span class="required">*</span></td>
                    <td><form:input path="startDate" cssClass="datetimepicker"/></td>
                    <td><form:errors path="startDate" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td>Finish Date <span class="required">*</span></td>
                    <td><form:input path="finishDate" cssClass="datetimepicker"/></td>
                    <td><form:errors path="finishDate" cssStyle="color:red"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td align="right"><input type="submit" value="submit" class="button" id="submit"></td>
                    <td></td>
                </tr>
            </table>
        </fieldset>
    </form:form>
</div>